function Chat() {
    that = this;
    this.chat = null;

    this.enabled = false;

    this.create = function () {
        var parent = dojo.byId("chatField");
        this.chat = cr("div", {id:"chat"}, parent);
        var text = cr("input", {type:"text"}, parent);
        cr("input", {type:"button", onclick:function () {
            callgo("put-chat", {message:text.value});
            text.value = "";
        }}, parent);
    };


    this.refresh = function () {
        if (this.enabled) {
            call("get-chat", {}, function (txt) {
                that.chat.innerHTML += txt;
            });
        }
    };

    this.on = function () {
        if (!$("chat")) {
            this.create();
        }
        this.enabled = true;
    };

    this.off = function () {
        this.enabled = false;
    };
}

chat = new Chat();